using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace Geomatrix
{
    class Help
    {
        int YPos = 0; //How far from the bottom of the screen the menu is;
        int LastY = 0;
        Texture2D _helpBack;
        String _helpStr;

        bool move;

        //Buttons:
        Button Quit;
        Button NewLevel;

        public Help(Texture2D helpBack, Texture2D butTex, String helpStr)
        {
            _helpBack = helpBack;
            _helpStr = helpStr;
            move = false;

            //Init Buttons:
            NewLevel = new Button(new Vector2(36, 0), butTex, "New Level");
            Quit = new Button(new Vector2(36, 0), butTex, "Main Menu");
        }

        public int Update(TouchCollection tc)
        {
            //Update the button positions/scroll
            foreach (TouchLocation tl in tc)
            {
                if (tl.State == TouchLocationState.Pressed && tl.Position.Y > 480 - YPos - 40)
                {
                    LastY = (int)tl.Position.Y;
                    move = true;
                }
                else if (tl.State == TouchLocationState.Released)
                    move = false;
                else if (move)
                {
                    YPos += LastY - (int)tl.Position.Y;
                    LastY = (int)tl.Position.Y;
                }
            }

            //If no button Pressed, than lower the help menu back down if it is not up all the way
            if (!move && YPos < 245)
            {
                YPos -= 20;
            }

            if (YPos < 0)
                YPos = 0;
            else if (YPos > 250)
                YPos = 250;

            //Move Buttons to Proper Place:
            Quit.SetPosition(new Vector2(36, 480 - YPos + 200));
            NewLevel.SetPosition(new Vector2(36, 480 - YPos + 152));
            //Update Buttons
            if (NewLevel.Update(tc))
            {
                YPos = 0;
                return 1;
            }
            if (Quit.Update(tc))
            {
                YPos = 0;
                return 2;
            }
            return 0;
        }

        public void Draw(SpriteBatch sb)
        {
            sb.Draw(_helpBack, new Vector2(10, 480 - YPos - 40), Color.White);

            Quit.Draw(sb);
            NewLevel.Draw(sb);
        }
    }
}